﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kooboo.IoC;
using Kooboo.Domain;

namespace Kooboo.Commerce.Domain.Services
{
    public class CountryService : ServiceBase<ICountryRepository, ICountry>
    {
        //internal CountryService()
        //{
        //}

        public override IQueryable<ICountry> QueryService
        {
            get {
                return this.Repository.Countries;
            }
        }

        #region Country
        public  void Post(ICountry country, bool hasTransaction = false)
        {
            

            using (var transaction = ObjectContainer.CreateInstance<TransactionContext>())
            {
                try
                {
                    this.Repository.Post(country);
                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

        }

        public  void Put(ICountry country, bool hasTransaction = false)
        {
          
            using (var transaction = ObjectContainer.CreateInstance<TransactionContext>())
            {
                try
                {
                    this.Repository.Put(country);
                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

        }

        public  void Delete(ICountry country, bool hasTransaction = false)
        {
            

            using (var transaction = ObjectContainer.CreateInstance<TransactionContext>())
            {
                try
                {
                    this.Repository.Delete(country);

                    transaction.Commit();
                }
                catch
                {
                    transaction.Rollback();
                    throw;
                }
            }

        }

        #endregion
    }


}
